<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>Markdown</title>
    <meta charset="UTF-8">
    <!-- 引入 highlight.js 库用于代码高亮 -->
    <link rel="stylesheet" th:href="@{https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.3.1/styles/default.min.css}">
    <script th:src="@{https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.3.1/highlight.min.js}"></script>
    <!-- 引入 tocbot 用于生成目录 -->
    <link rel="stylesheet" th:href="@{https://cdn.jsdelivr.net/npm/tocbot/dist/tocbot.min.css}">
    <script th:src="@{https://cdn.jsdelivr.net/npm/tocbot/dist/tocbot.min.js}"></script>
    <style>
        /* 自定义样式 */
        .markdown-content {
            max-width: 800px;
            margin: 0 auto;
            padding: 30px;
        }
        #toc {
            position: fixed;
            right: 30px;
            top: 30px;
            max-width: 200px;
        }
    </style>
</head>
<body>
<div class="markdown-content" th:utext="${htmlContent}"></div>
<nav id="toc"></nav>
<script>
    // 启用代码高亮
    document.addEventListener('DOMContentLoaded', (event) => {
        document.querySelectorAll('pre code').forEach((block) => {
            hljs.highlightBlock(block);
        });
    });

    // 配置并启用 tocbot
    tocbot.init({
        tocSelector: '#toc',
        contentSelector: '.markdown-content',
        headingSelector: 'h1, h2, h3, h4',
        hasInnerContainers: true,
        collapseDepth: 6
    });
</script>
</body>
</html>